package com.maxd.modules.selfshop.merchants.respository;


import com.maxd.modules.selfshop.merchants.entity.SelfStoreCollect;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface SelfStoreCollectJpaRepository extends JpaRepository<SelfStoreCollect, Long> {

    //分页查询
    Page<SelfStoreCollect> findAll(Pageable pageable);

    //条件查询
    Page<SelfStoreCollect> findAll(Specification<SelfStoreCollect> specification, Pageable pageable);

    //根据商品id和用户id查询来判断是否收藏
    @Query(value = "from SelfStoreCollect s where s.storeId=:storeId and s.userId=:userId")
    SelfStoreCollect findByStoreIdAndUserId(@Param("storeId") Long storeId, @Param("userId") Long userId);

    //根据店铺id统计
    @Query(value = "select count(s.id) from SelfStoreCollect s where s.storeId=:storeId")
    int findByStoreId(@Param("storeId") Long storeId);

}
